package com.ljf.framework.util;

import com.ljf.framework.exception.LjfException;

import java.util.HashMap;

/**
 * 说明：
 *
 * @Auther: lijinfeng
 * @Date: 2023/9/18
 */
public class LjfMapUtil {

    /**
     * 将objectStringToMap串转化为map
     * 格式
     * {password=123456, LJF-TOKEN=53e2d5da-4959-4084-9997-5077be61d14e, username=qw}
     *
     * @param str
     * @return
     */
    public static HashMap objectStringToMap(String str) {
        HashMap<String, String> map = new HashMap<>();
        try {
            String replace = str.replace("{", "").replace("}","");
            String[] kvs = replace.split(",");
            for (String kv : kvs){
                String[] split = kv.split("=");
                map.put(split[0].replace("\"", "").trim(), split[1].replace("\"", "").trim());
            }
        }catch (Exception e){
            throw new LjfException("非规定格式");
        }
        return map;
    }


}
